<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件处理</title>
    <script src="../js/vue.js"></script>
    <style>

    </style>
</head>

<body>
    <div id="root">
        姓：<input type="text" v-model="firstName"> <br>
        名：<input type="text" v-model="lastName"> <br>
        全名：<span>{{fullName}}</span>
    </div>
    <script>
        Vue.config.productionTip = false

        const vm = new Vue({
            el: '#root',
            data: {
                firstName: '张',
                lastName: '三'
            },
            //计算属性
            computed: {
                fullName: {
                    //当有人读取fullName时，get就会别调用，且返回值就是fullName的值
                    get() {
                        console.log('fullName 被调用了！')
                        return this.firstName + '-' + this.lastName;
                    },
                    //当fullName被修改的时候
                    set(value) {
                        console.log(value);
                        const arr = value.split('-');
                        this.firstName = arr[0];
                        this.lastName = arr[1]
                    }
                }
            }
        })
    </script>
</body>

</html>